'use strict';
const { v4: uuidv4 } = require('uuid');

const db = uniCloud.database()
exports.main = async (event, context) => {
	let {accountNumber, password} = event;
	
	// 检查用户名是否已存在
	const user = await db.collection('users').where({
		accountNumber
	}).get()

	if (user.data.length > 0) {
		return {
		  code: 400,
		  message: '用户名已存在'
		}
	}
	
	
	await db.collection("users").add({
		accountNumber,
		password,
		uuid: uuidv4()
	});
	
	return {
		code: 200,
		message: '注册成功'
	}

};
